package logic.projectiles;

import java.awt.Rectangle;
import java.awt.geom.Line2D;

import logic.blocks.Block;
import logic.enemies.Enemy;
import logic.entities.GameObject;
import logic.pruebas.GamePanel;

/**
 * @author Unai
 * Bola de fuego que avanza rebotando
 *
 */
public class FireBall extends Projectile{
	private static final long serialVersionUID = 980349337543285229L;

	public FireBall(float x, float y, GamePanel panel, String nomImg, boolean direction, int damage) {
		super(x, y, panel, nomImg);
		// TODO Auto-generated constructor stub
		falling = true;
		if (direction) {
			velX = 350;
		} else {
			velX = -350;
		}
		this.damage = damage;
	}

	public void impact(GameObject object) {
		if (dibujado) {
			if (object.dibujado && !object.dead) {
				Line2D pUp = new Line2D.Float(object.coorX + 5, object.coorY, object.coorX + object.anchura - 7, object.coorY);
				Rectangle objRectangle = new Rectangle((int)object.coorX, (int)object.coorY, object.anchura, object.altura);
				Rectangle thisObject = new Rectangle((int)coorX, (int)coorY, anchura, altura);

				if (pUp.intersects(thisObject)) {
					if (object instanceof Block) {
						jump();
					}
				} else if (objRectangle.intersects(thisObject)) {
					if (object instanceof Enemy) {
						Enemy tempE = (Enemy) object;
						tempE.magicDamage(damage);
					}
					impacted = true;
				}

			}
		}
	}

	public void jump() {
		velY = -200;
	}

}
